package com.idanchuang.count.core.util;

import com.idanchuang.user.count.service.api.response.BatchUserSceneCountDTO;
import com.idanchuang.user.count.service.api.response.UserMultiScenesCountDTO;
import com.idanchuang.user.count.service.api.response.UserSceneCountDTO;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Richard_yyf
 * @version 1.0 2021/5/27
 */
public class CountDtoAssembler {

    public static BatchUserSceneCountDTO buildBatchUserSceneCountDTO(Integer userCode,
                                                                     List<String> scenes,
                                                                     List<Integer> userMsgCountList,
                                                                     List<Integer> sysMsgCountList) {
        BatchUserSceneCountDTO dto = new BatchUserSceneCountDTO();
        dto.setUserCode(userCode);

        Map<String, Integer> sceneCountMap = new HashMap<>(scenes.size());
        int total = 0;
        for (int i = 0; i < scenes.size(); i++) {
            total = total + userMsgCountList.get(i) + sysMsgCountList.get(i);
            sceneCountMap.put(scenes.get(i), userMsgCountList.get(i) + sysMsgCountList.get(i));
        }
        dto.setSceneCountMap(sceneCountMap);
        dto.setTotalCount(total);

        return dto;
    }

    public static UserSceneCountDTO buildUserSceneCountDTO(Integer userCode, String scene,
                                                           Integer count) {
        UserSceneCountDTO dto = new UserSceneCountDTO();
        dto.setUserCode(userCode);
        dto.setScene(scene);
        dto.setCount(count);
        return dto;
    }

    public static UserMultiScenesCountDTO buildUserMultiScenesCountDTO(Integer userCode, Map<String, Integer> scenesCountMap) {
        UserMultiScenesCountDTO dto = new UserMultiScenesCountDTO();
        dto.setUserCode(userCode);
        dto.setScenesCountMap(scenesCountMap);
        return dto;
    }
}
